package com.example.zbh.lessona.eventbus;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zbh.lessona.R;

import de.greenrobot.event.EventBus;

/**
 * Created by zbh on 15/12/2.
 */
public class RightFragment extends Fragment {
    private TextView textView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);


    }
    //该方法与发布者同一个线程执行
    public void onEvent(Integer data){
        Log.i("nanchaodong", "------>>" + Thread.currentThread().getId());
        Log.i("nanchaodong", "------>>返回数据" + data);
        textView.setText(data + "");
    }

    //该方法在ui主线程中执行
    public void onEventMainThread(String data){
        Log.i("nanchaodong", "--onEventMainThread---->>" + Thread.currentThread().getId());
        Log.i("nanchaodong", "----onEventMainThread-->>返回数据" + data);
        textView.setText(data);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_right, container, false);
        textView = (TextView) view.findViewById(R.id.textView);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
    }

    private void init() {


    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
    }
}
